const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const CompressionWebpackPlugin = require("compression-webpack-plugin");

const productionGzipExtensions = ["js", "css"];

const env = process.env.NODE_ENV;

module.exports = {
  outputDir: "dist/portal", //打包地址
  publicPath: "/portal/", // 部署应用包时的基本 URL
  configureWebpack: config => {
    if (env !== "development" || env !== "test") {
      config.plugins.push(
        new CompressionWebpackPlugin({
          algorithm: "gzip",
          test: new RegExp(`\\.(${productionGzipExtensions.join("|")})$`),
          threshold: 10240,
          minRatio: 0.8
        })
      );
      config.plugins.push(
        new UglifyJsPlugin({
          uglifyOptions: {
            warnings: false,
            compress: {
              drop_debugger: true, // console
              drop_console: true,
            //   pure_funcs: ["console.log"] // 移除console
            }
          },
          sourceMap: false,
          parallel: true
        })
      );
    }
  }
};
